package com.yiwei.zhh.impl;

import android.content.Context;

import com.yiwei.zhh.constant.Const;
import com.yiwei.zhh.http.CallBackListener;
import com.yiwei.zhh.http.InterfaceServer;
import com.yiwei.zhh.interfaces.PayInfo;
import com.yiwei.zhh.http.InfoCallBack;
import com.yiwei.zhh.model.AlipayModel;
import com.yiwei.zhh.model.RequestModel;
import com.yiwei.zhh.model.YijipayModel;

import java.util.HashMap;
import java.util.Map;

/**
 * 支付数据
 * Created by Master.Dong on 2016/4/13.
 */
public class PayInfoImpl implements PayInfo {

    /**
     * 支付宝支付
     *
     * @param mContext
     * @param payment_notice_id
     * @param callBack
     */
    @Override
    public void getAlipayInfo(Context mContext, String payment_notice_id, final InfoCallBack callBack) {
        Map<String, Object> mapData = new HashMap<String, Object>();
        mapData.put("payment_notice_id", payment_notice_id);
        RequestModel model = new RequestModel(mapData);

        InterfaceServer.getInstance(mContext.getApplicationContext()).requestInterface(Const.ALIPAY_PARAMS, Const.RequestMethod.POST, model, Const.DEFAULT_TIMEOUT, new CallBackListener<AlipayModel>(AlipayModel.class,callBack));
//                new ResponseListener() {
//            @Override
//            public void onStartInMainThread(Object result) {
//                callBack.onFailure(result.toString());
//            }
//
//            @Override
//            public void onFinishInMainThread(Object result) {
//            }
//
//            @Override
//            public Object onSuccessInRequestThread(int statusCode, String content) {
//                try {
//                    return JsonUtil.<AlipayModel>fromJson(content, AlipayModel.class);
//                } catch (Exception e) {
//                    return null;
//                }
//            }
//
//            @Override
//            public void onSuccessInMainThread(int statusCode, String content, Object result) {
//                try {
//                    AlipayModel model = (AlipayModel) result;
//                    if (model.getStatus() == 1)
//                        callBack.onSuccess(model);
//                    else callBack.onFailure(model.getMsg());
//                    //返回数据接口
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        });
    }

    /**
     * 已支付
     *
     * @param mContext
     * @param payment_notice_id
     * @param callBack
     */
    @Override
    public void getYijipayInfo(Context mContext, String payment_notice_id, final InfoCallBack callBack) {
        Map<String, Object> mapData = new HashMap<String, Object>();
        mapData.put("payment_notice_id", payment_notice_id);
        RequestModel model = new RequestModel(mapData);

        InterfaceServer.getInstance(mContext.getApplicationContext()).requestInterface(Const.YIJIPAY_PARAMS, Const.RequestMethod.POST, model, Const.DEFAULT_TIMEOUT, new CallBackListener<YijipayModel>(YijipayModel.class,callBack));
//                new ResponseListener() {
//            @Override
//            public void onStartInMainThread(Object result) {
//                callBack.onFailure(result.toString());
//            }
//
//            @Override
//            public void onFinishInMainThread(Object result) {
//            }
//
//            @Override
//            public Object onSuccessInRequestThread(int statusCode, String content) {
//                try {
//                    return JsonUtil.<YijipayModel>fromJson(content, YijipayModel.class);
//                } catch (Exception e) {
//                    return null;
//                }
//            }
//
//            @Override
//            public void onSuccessInMainThread(int statusCode, String content, Object result) {
//                try {
//                    YijipayModel model = (YijipayModel) result;
//                    if (model.getStatus() == 1)
//                        callBack.onSuccess(model);
//                    else callBack.onFailure(model.getMsg());
//                    //返回数据接口
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        });
    }
}
